package com.servlet;

import com.DAO.GoodsDaoImpl;
import com.entity.Goods;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.util.List;

@WebServlet("/queryGoods")
public class QueryGoodsServlet extends HttpServlet {
    private GoodsDaoImpl goodsDaoImpl = new GoodsDaoImpl();
    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("application/json;charset=UTF-8");
        List<Goods> goodsList = goodsDaoImpl.getAllGoods();
        Gson gson = new Gson();
        String jsonData = gson.toJson(goodsList);
        response.getWriter().write(jsonData);
    }
} 